package adventure.vocation;

import adventure.commands.skills.Skill;
import java.util.ArrayList;

/**
 *
 * @author Michael Hanns
 *
 */
public class VocationManagerImp implements VocationManager {

    private ArrayList<Vocation> vocations;

    public VocationManagerImp() {
        vocations = new ArrayList<Vocation>();
        vocations.add(new VocationImp(0));
    }

    @Override
    public void newVocation() {
        vocations.add(new VocationImp(vocations.size()));
    }
    
    @Override
    public void newVocation(VocationEdit v) {
        vocations.add((Vocation)v);
    }

    @Override
    public int totalVocations() {
        return vocations.size()-1;
    }

    @Override
    public Vocation getVocation(int id) {
        for (int c = 0; c < vocations.size(); c++) {
            if (vocations.get(c).getID() == id) {
                return vocations.get(c);
            }
        }
        return new VocationImp(0);
    }

    @Override
    public void removeVocation(int id) {
        for (int c = 0; c < vocations.size(); c++) {
            if (vocations.get(c).getID() == id) {
                vocations.remove(c);
            }
        }
    }

    @Override
    public boolean addSkill(int id, Skill skill) {
        for (int c = 0; c < vocations.size(); c++) {
            if (vocations.get(c).getID() == id) {
                return vocations.get(c).learnSkill(skill);
            }
        }
        return false;
    }

    @Override
    public boolean removeSkill(int id, int skillPos) {
        for (int c = 0; c < vocations.size(); c++) {
            if (vocations.get(c).getID() == id) {
                return ((VocationEdit)vocations.get(c)).removeSkill(skillPos);
            }
        }
        return false;
    }
}
